-- delete backup/job history prior to a specified date
DECLARE @CleanupDate DATETIME =
	DATEADD(day, -30, GETDATE());

EXECUTE msdb.dbo.sp_delete_backuphistory @oldest_date = @CleanupDate;

EXECUTE msdb.dbo.sp_purge_jobhistory @oldest_date = @CleanupDate;

-- Ola Hallengren maintenance solution
DELETE FROM master.dbo.CommandLog WHERE StartTime < @CleanupDate;


-- delete the backup history for a specific database 
EXECUTE msdb.dbo.sp_delete_database_backuphistory N'<database_name>';